<template>
<div>
    <div class="campus-delivery-status-desc">
        <!-- 提示栏 -->
        <el-button type="primary" plain>状态描述:</el-button>
        <el-button type="success">1:已投递</el-button>
        <el-button type="info">2:进行中</el-button>
        <el-button type="danger">3:被录用</el-button>
        <el-button type="warning">4:流程终止</el-button>
        <el-button>5:撤销投递</el-button>
    </div>
    <div>
        <!-- 表格区域 -->
        <el-table :data="tableList" style="width: 100%">
            <el-table-column label="投递日期" width="260" sortable>
                <template slot-scope="scope">
                    <el-date-picker v-model="scope.row.time" type="datetime" :readonly="true"></el-date-picker>
                </template>
            </el-table-column>
            <el-table-column label="候选人" width="150" prop="gname">
            </el-table-column>
            <el-table-column label="职位名称" width="150" prop="name">
            </el-table-column>
            <el-table-column label="投递状态" width="100" prop="status">
            </el-table-column>
            <el-table-column label="操作" width="320">
                <template slot-scope="scope">
                    <el-button size="mini" icon="el-icon-view" type="info" @click="viewResume(scope.$index, scope.row)">查看简历</el-button>
                    <el-button size="mini" icon="el-icon-remove" type="danger" @click="refuse(scope.$index, scope.row)">拒绝</el-button>
                    <el-button size="mini" icon="el-icon-success" type="success" @click="popApply(scope.$index, scope.row)">直接录用</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
    <!-- 分页插件 -->
    <div class="campus-enterprise-page">
        <el-pagination background layout="prev, pager, next" :current-page="pageInfo.current" :page-size="pageInfo.pageSize" :page-count="11" :total="total" @current-change="clickQueryByPage"></el-pagination>
    </div>
    <!-- 查看简历对话框 -->
    <el-dialog title="查看简历" :visible.sync="dialogFormVisible" modal :append-to-body="true" v-loading="loading" element-loading-text="发送中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)">
        <!-- 简历描述 -->
        <el-descriptions title="简历内容">
            <el-descriptions-item label="候选人名称">{{
          resumeDesc.gname
        }}</el-descriptions-item>
            <el-descriptions-item label="性别">{{
          resumeDesc.sex
        }}</el-descriptions-item>
            <el-descriptions-item label="年龄">{{
          resumeDesc.age
        }}</el-descriptions-item>
            <el-descriptions-item label="生日">
                <el-date-picker :readonly="true" v-model="resumeDesc.birthday" type="date" style="width: 140px">
                </el-date-picker>
            </el-descriptions-item>
            <el-descriptions-item label="毕业院校">{{
          resumeDesc.schoolname
        }}</el-descriptions-item>
            <el-descriptions-item label="学历">{{
          resumeDesc.education
        }}</el-descriptions-item>
            <el-descriptions-item label="家庭住址">{{
          resumeDesc.address
        }}</el-descriptions-item>
            <el-descriptions-item label="意向城市">{{
          resumeDesc.city
        }}</el-descriptions-item>
            <el-descriptions-item label="目前身份">{{
          resumeDesc.identify
        }}</el-descriptions-item>
            <el-descriptions-item label="求职意向">{{
          resumeDesc.position
        }}</el-descriptions-item>
            <el-descriptions-item label="期望薪水">{{
          resumeDesc.salary
        }}</el-descriptions-item>
            <el-descriptions-item label="联系方式">{{
          resumeDesc.email
        }}</el-descriptions-item>
            <el-descriptions-item label="我的优势">{{
          resumeDesc.advantage
        }}</el-descriptions-item>
        </el-descriptions>
        <!-- 邮件内容 -->
        <el-divider>邮件内容</el-divider>
        <div>
            <el-form ref="form" :model="emailForm" :rules="emailFormRules" label-width="80px" :inline="true">
                <el-form-item label="邮件标题" label-width="80px" prop="interviewTitle">
                    <el-input v-model="emailForm.interviewTitle"></el-input>
                </el-form-item>
                <el-form-item label="面试时间" label-width="80px" prop="interviewTime">
                    <el-date-picker v-model="emailForm.interviewTime" type="datetime" placeholder="选择日期时间" align="right" :picker-options="pickerOptions">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="面试地点" label-width="80px" prop="interviewLocaltion">
                    <el-input v-model="emailForm.interviewLocaltion"></el-input>
                </el-form-item>
                <el-form-item label="面试形式" label-width="80px" prop="interviewForm">
                    <el-input v-model="emailForm.interviewForm"></el-input>
                </el-form-item>
                <el-form-item label="接收邮箱" label-width="80px" prop="interviewQQ">
                    <el-input v-model="emailForm.interviewQQ"></el-input>
                </el-form-item>
                <el-form-item label="联系方式" label-width="80px" prop="interviewLink">
                    <el-input v-model="emailForm.interviewLink"></el-input>
                </el-form-item>
                <el-form-item label="面试链接" label-width="80px">
                    <el-input v-model="emailForm.interviewHref"></el-input>
                </el-form-item>
                <el-form-item label="面试寄语" label-width="80px" prop="interviewMessage">
                    <el-input type="textarea" v-model="emailForm.interviewMessage"></el-input>
                </el-form-item>
            </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="sendEmail">发送面试邮件</el-button>
        </div>
    </el-dialog>
    <!-- 直接录用对话框 -->
    <el-dialog title="录用邮件" :visible.sync="dialogApplyFormVisible" modal :append-to-body="true" v-loading="applyLoading" element-loading-text="发送中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)">
        <el-form :model="applyForm" :rules="applyFormRules" ref="applyFormRef" :inline="true">
            <el-form-item label="邮件标题" :label-width="formLabelWidth" prop="title">
                <el-input v-model="applyForm.title" autocomplete="off" style="width: 150px"></el-input>
            </el-form-item>
            <el-form-item label="公司" :label-width="formLabelWidth" prop="company">
                <el-input v-model="applyForm.company" autocomplete="off" style="width: 150px"></el-input>
            </el-form-item>
            <el-form-item label="岗位" :label-width="formLabelWidth" prop="position">
                <el-input v-model="applyForm.position" autocomplete="off" style="width: 150px"></el-input>
            </el-form-item>
            <el-form-item label="候选人邮箱" :label-width="formLabelWidth" prop="email">
                <el-input v-model="applyForm.email" autocomplete="off" style="width: 150px"></el-input>
            </el-form-item>
            <el-form-item label="联系方式" :label-width="formLabelWidth" prop="link">
                <el-input v-model="applyForm.link" autocomplete="off" style="width: 150px"></el-input>
            </el-form-item>
            <el-form-item label="报道时间" :label-width="formLabelWidth" prop="time">
                <el-date-picker v-model="applyForm.time" type="date" placeholder="选择日期时间" align="right" style="width: 150px"></el-date-picker>
            </el-form-item>
            <el-form-item label="录用祝福" :label-width="formLabelWidth" prop="message">
                <el-input v-model="applyForm.message" type="textarea" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogApplyFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="employment">发送录用通知</el-button>
        </div>
    </el-dialog>
</div>
</template>

<script>
export default {
    name: "RecommendViewpositing",

    data() {
        return {
            // 查看简历参数
            viewResumeObj: {
                gid: 0,
            },
            // 拒绝参数
            refuseObj: {
                did: 0,
            },
            // 录用邮件表单
            applyForm: {
                title: "",
                company: "",
                position: "",
                email: "",
                link: "",
                time: new Date(),
                message: "",
                did: 0,
            },
            //
            pickerOptions: {
                shortcuts: [{
                        text: "今天",
                        onClick(picker) {
                            picker.$emit("pick", new Date());
                        },
                    },
                    {
                        text: "昨天",
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit("pick", date);
                        },
                    },
                    {
                        text: "一周前",
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit("pick", date);
                        },
                    },
                ],
            },
            // 邮件内容
            emailForm: {
                interviewTime: new Date(),
                interviewLocaltion: "",
                interviewForm: "",
                interviewHref: "",
                interviewMessage: "",
                interviewLink: "",
                interviewTitle: "",
                interviewQQ: "",
                did: 0,
            },
            // 邮件表单验证
            emailFormRules: {
                interviewTitle: [{
                    required: true,
                    message: "邮件标题不能为空",
                    trigger: "blur",
                }, ],
                interviewTime: [{
                    required: true,
                    message: "面试时间不能为空",
                    trigger: "blur",
                }, ],
                interviewLocaltion: [{
                    required: true,
                    message: "面试地点不能为空",
                    trigger: "blur",
                }, ],
                interviewForm: [{
                    required: true,
                    message: "面试形式不能为空",
                    trigger: "blur",
                }, ],
                interviewLink: [{
                    required: true,
                    message: "联系方式不能为空",
                    trigger: "blur",
                }, ],
                interviewQQ: [{
                    required: true,
                    message: "候选人邮箱账号不能为空",
                    trigger: "blur",
                }, ],
                interviewMessage: [{
                    required: true,
                    message: "面试寄语不能为空",
                    trigger: "blur",
                }, ],
            },
            // 录用表单验证
            applyFormRules: {
                title: [{
                    required: true,
                    message: "标题不能为空",
                    trigger: "blur",
                }, ],
                company: [{
                    required: true,
                    message: "公司不能为空",
                    trigger: "blur",
                }, ],
                position: [{
                    required: true,
                    message: "岗位不能为空",
                    trigger: "blur",
                }, ],
                email: [{
                    required: true,
                    message: "候选人邮箱不为空",
                    trigger: "blur",
                }, ],
                link: [{
                    required: true,
                    message: "联系方式不能为空",
                    trigger: "blur",
                }, ],
                time: [{
                    required: true,
                    message: "报道时间不能为空",
                    trigger: "blur",
                }, ],
                message: [{
                    required: true,
                    message: "内容不能为空",
                    trigger: "blur",
                }, ],
            },
            dialogFormVisible: false,
            dialogApplyFormVisible: false,
            // 简历描述
            resumeDesc: {
                rid: 0,
                gid: 0,
                gname: "",
                schoolname: "",
                education: "",
                address: "",
                city: "",
                email: "",
                identify: "",
                advantage: "",
                position: "",
                salary: 0,
                sex: "",
                age: 0,
                birthday: new Date(),
            },
            // 分页参数
            pageInfo: {
                current: 1,
                pageSize: 5,
            },
            // 总条数
            total: 0,
            formLabelWidth: "120px",
            // 面试邮件发送中
            loading: false,
            // 录用邮件发送中
            applyLoading: false,
            // 表格数据
            tableList: [],
        };
    },

    mounted() {
        this.LoadTableList();
    },

    methods: {
        // 加载数据
        LoadTableList() {
            this.$axios
                .post("/delivery/queryDeliveryByHid", this.pageInfo)
                .then((res) => {
                    if (res.data.result.list != null) {
                        this.tableList = res.data.result.list;
                        this.total = res.data.result.totalCounts;
                    } else {
                        return;
                    }
                })
                .catch((error) => {
                    console.log(error);
                    this.$message({
                        message: "系统错误!!!",
                        type: "error",
                    });
                });
        },
        // 查看简历
        viewResume(index, row) {
            console.log(index, row);
            this.viewResumeObj.gid = row.gid;
            console.log(row.gid);
            this.$axios
                .post("/resume/viewResume", this.viewResumeObj)
                .then((res) => {
                    if (res.data.result != null) {
                        this.resumeDesc = res.data.result;
                        this.emailForm.did = row.did;
                    }
                    // 打开对话框
                    this.dialogFormVisible = true;
                })
                .catch((error) => {
                    console.log(error);
                    this.$message({
                        message: "系统错误!!!",
                        type: "error",
                    });
                });
        },
        // 发送面试邮件
        sendEmail() {
            // 表单验证
            this.$refs.form.validate((valid) => {
                if (!valid) {
                    this.$message({
                        message: "填写不能为空",
                        type: "error",
                    });
                    return;
                } else {
                    this.loading = true;
                }
            });
            // 验证通过发送请求
            this.$axios
                .post("/resume/sendInterviewEmail", this.emailForm)
                .then((res) => {
                    var response = res.data.desc;
                    if (response === "发送失败") {
                        this.$message({
                            message: "亲,发送失败,可能是邮箱地址不正确...",
                            type: "error",
                        });
                        this.loading = false;
                        return;
                    } else if (response === "发送成功") {
                        this.$message({
                            message: "发送成功",
                            type: "success",
                        });
                        this.LoadTableList();
                        this.loading = false;
                        this.dialogFormVisible = false;
                    }
                })
                .catch((error) => {
                    console.log(error);
                    this.$message({
                        message: "系统错误!!!",
                        type: "error",
                    });
                });
        },
        // 拒绝
        refuse(index, row) {
            console.log(index, row);
            this.refuseObj.did = row.did;
            this.$axios
                .post("/delivery/refuseDelivery", this.refuseObj)
                .then((res) => {
                    var response = res.data.desc;
                    if (response === "拒绝失败") {
                        this.$message({
                            message: "操作失败",
                            type: "error",
                        });
                        return;
                    } else if (response === "拒绝成功") {
                        this.LoadTableList();
                        this.$message({
                            message: "操作成功",
                            type: "success",
                        });
                    }
                })
                .catch((error) => {
                    console.log(error);
                    this.$message({
                        message: "系统错误!!!",
                        type: "error",
                    });
                });
        },
        // 打开录用对话框
        popApply(index, row) {
            console.log(index, row);
            this.applyForm.did = row.did;
            this.dialogApplyFormVisible = true;
        },
        // 直接录用
        employment() {
            this.$refs.applyFormRef.validate((valid) => {
                if (!valid) {
                    this.$message({
                        message: "不能发送空的内容",
                        type: "error",
                    });
                    return;
                } else {
                    this.applyLoading = true;
                }
            });
            this.$axios
                .post("/resume/sendApplyEmail", this.applyForm)
                .then((res) => {
                    var response = res.data.desc;
                    if (response === "发送失败") {
                        this.$message({
                            message: "发送失败",
                            type: "error",
                        });
                        this.applyLoading = false;
                        return;
                    } else if (response === "发送成功") {
                        this.$message({
                            message: "发送成功",
                            type: "success",
                        });
                        this.LoadTableList();
                        this.applyLoading = false;
                        this.dialogApplyFormVisible = false;
                    }
                })
                .catch((error) => {
                    console.log(error);
                    this.$message({
                        message: "系统错误!!!",
                        type: "error",
                    });
                });
        },
        // 分页
        clickQueryByPage(current) {
            this.pageInfo.current = current;
            this.LoadTableList();
        },
    },
};
</script>

<style scoped>
.campus-delivery-status-desc {
    width: 100%;
    height: 80px;
    line-height: 80px;
}

.campus-enterprise-page {
    margin: 10px 300px;
}
</style>
